#pragma once
#include <vector>
#include "DataPointManager.h"
#include "cv.h"

typedef std::vector<CvRect> TRectVec;
typedef std::vector<CvRect>::iterator TRectVecIter;

class CObjectExtractor
{
public:
	CObjectExtractor(void);
	virtual ~CObjectExtractor(void);
	CDataPointManager * GetAllObjectsInFrame( IplImage * img ); 
	void SetThreshold( int thresh );
	int GetThreshold( void );
	void SetMinSize( int minSize );
	int GetMinSize( void );
	void SetMaxSize( int maxSize );
	int GetMaxSize( void );
	void SetMinWH( int minWH );
	int GetMinWH( void ); 
	

	
	TRectVec GetObjectCentroids( void );

protected:
	bool BoundsGood( IplImage * img, int w, int h, int x, int y );
	bool BoundsGoodROI( IplImage * img, int w, int h, int x, int y); 
	void DoIntersectionTests(void);
	bool Intersect(CvRect a, CvRect b );
	CvRect Merge(CvRect a, CvRect b);
	TRectVec GetObjectsInFrame( IplImage * img ); 
	IplImage * RotateObjectToCanonicalForm( IplImage * img ); 
	void ApplyRotation( IplImage* input, IplImage * output, CvPoint2D32f center, float angle );
	void FlipToCOMOnTop(IplImage* input ); // Flip the image 180 if the COM is over a certain threshold 
	double GetLargestContourMass( IplImage * imp ); 
	TRectVec m_objectCentroids;
	CvMemStorage* m_memStorage;
	CvSeq* m_contour;
	int m_c;
	int m_threshold;
	int m_minSize;
	int m_maxSize;
	int m_minWH;

};
